package com.dgut.service.serviceImpl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dgut.common.ExamineState;
import com.dgut.mapper.OrderEvaluationMapper;
import com.dgut.pojo.Notice;
import com.dgut.pojo.OrderEvaluation;
import com.dgut.service.OrderEvaluationService;
import com.dgut.utils.PageRequestInfo;
import com.dgut.utils.PageResult;
import com.dgut.utils.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Service
public class OrderEvaluationServiceImpl implements OrderEvaluationService {
    @Resource
    private OrderEvaluationMapper orderEvaluationMapper;


    /**
     * start-zwb
     */
    @Override
    public Object addOrderEvaluation(OrderEvaluation orderEvaluation)
    {
        ConcurrentHashMap resultMap = new ConcurrentHashMap();
        if(orderEvaluationMapper.insert(orderEvaluation)>0)
        {
            resultMap.put("result",true);
            resultMap.put("message","更新成功！");
        }
        else
        {
            resultMap.put("result",false);
            resultMap.put("message","更新失败！");
        }
        return resultMap;
    }
    /**
     * end-zwb
     */


    /**
     * start-gxd
     */
    /**
     * end-gxd
     */


    /**
     * start-lzh
     */
    /**
     * end-lzh
     */

    /**
     * start-hwf
     */

    @Override
    public PageResult getSuccessOrderEvaluation(PageRequestInfo pageRequestInfo) {
        Page<OrderEvaluation> page = new Page<>(pageRequestInfo.getPageNum(),pageRequestInfo.getPageSize());
        Page<OrderEvaluation> pageResult = orderEvaluationMapper.selectPage(page, Wrappers.<OrderEvaluation>lambdaQuery().eq(OrderEvaluation::getState, ExamineState.SUCCESS));
        return PageUtils.getPageResult(pageResult);
    }

    @Override
    public PageResult getFailOrderEvaluation(PageRequestInfo pageRequestInfo) {
        Page<OrderEvaluation> page = new Page<>(pageRequestInfo.getPageNum(),pageRequestInfo.getPageSize());
        Page<OrderEvaluation> pageResult = orderEvaluationMapper.selectPage(page, Wrappers.<OrderEvaluation>lambdaQuery().eq(OrderEvaluation::getState, ExamineState.FAIL));
        return PageUtils.getPageResult(pageResult);
    }

    @Override
    public PageResult getUnapprovedOrderEvaluation(PageRequestInfo pageRequestInfo) {
        Page<OrderEvaluation> page = new Page<>(pageRequestInfo.getPageNum(),pageRequestInfo.getPageSize());
        Page<OrderEvaluation> pageResult = orderEvaluationMapper.selectPage(page, Wrappers.<OrderEvaluation>lambdaQuery().eq(OrderEvaluation::getState, ExamineState.NOT_APPROVED));
        return PageUtils.getPageResult(pageResult);
    }

    @Override
    public boolean changeStateOrderEvaluation(int id, String state) {
        if(orderEvaluationMapper.changeStateOrderEvaluation(id,state) >= 1){
            return true;
        }else{
            return false;
        }
    }


    /**
     * end-hwf
     */
}
